//
//  NavigationbarBack.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/12.
//

import Foundation
import SwiftUI

struct NavigationbarBack:ViewModifier {
    @Environment(\.dismiss) var dismiss
    func body(content: Content) -> some View {
        content.navigationBarBackButtonHidden(true)
            .toolbar {
                ToolbarItem(placement: .topBarLeading) {
                 Image(systemName: "arrow.backward.square.fill")
                        .resizable()
                        .frame(width: 24, height: 24)
                        .accentColor(Color("color_text_main"))
                        .shakeTapGes {
                            dismiss()
                        }
                }
            }
            .toolbar(.hidden, for: .tabBar)
    }
}

extension View {
    func navigationBack() -> some View {
        modifier(NavigationbarBack())
    }
}


extension UINavigationController: @retroactive UIGestureRecognizerDelegate {
    override open func viewDidLoad() {
        super.viewDidLoad()
        interactivePopGestureRecognizer?.delegate = self
    }
    public func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        return viewControllers.count > 1
    }
}

